* Reset settings and initialize log file
launch, path("share/careers")

*-------------------------------------------------------------------------------
* Price and Wasserman (2024), "The Summer Drop in Female Employment"
*
* Description: Show how career choices vary over the life-cycle.
*-------------------------------------------------------------------------------


* Prepare data and run models
*-------------------------------------------------------------------------------

if "$estimate" != "0" {
	* Load data on adult individuals
	gzuse pid tm year month mish wtfinl tmspline* female age youngest_years emp school using "$basepath/data/derived/cps_bms_sample_allages.dta.gz", clear

	* Retain a broader-than-usual age range
	keep if inrange(age, 20, 64)

	* Focus on observations during the school year
	drop if inlist(month, 6, 7, 8)

	* Restrict to employed individuals
	keep if emp == 1

	* Prepare age of youngest child for use in regressions
	rename youngest_years childage
	replace childage = 18 if childage == .

	foreach f of numlist 0 1 {
		* Raw relationship between age of youngest child and share in education
		ivreg2 school ibn.childage if female == `f' [aw = wtfinl], noconstant cluster(pid tm) robust small
		estimates save "$basepath/models/careers/f`f'_raw.ster", replace

		* Regression-adjusted relationship between age of youngest child and share in education
		ivreg2 school ib0.childage i.age tmspline* if female == `f' [aw = wtfinl], cluster(pid tm) robust small
		estimates save "$basepath/models/careers/f`f'_adj.ster", replace
	}
}


* Prepare estimates
*-------------------------------------------------------------------------------

* Load estimates into memory
load_estimates, path("careers")


* Plot share employed in education by age of youngest child
*-------------------------------------------------------------------------------

* Prepare background shading
clear
set obs 14
gen rmin = .
gen rmax = .
gen rval = .

* Plot estimates
foreach k in "raw" "adj" {
	if "`k'" == "raw" {
		local title "Raw shares"
		local ytitle "Percent of employed"
		replace rmin = 0
		replace rmax = 18
		replace rval = _n - 0.5
		local yrange "0 18"
		local ylabel "0(3)18"
	}
	else if "`k'" == "adj" {
		local title "Adjusted for own-age and time effects"
		local ytitle "Percent of employed ({&lt} 1 year = 0)"
		replace rmin = -2
		replace rmax = 4
		replace rval = _n - 0.5
		local yrange "-2 4"
		local ylabel "-2(1)4"
	}

	#delimit ;
	coefplot
		(f1_`k', keep(*.childage) drop(18.childage) offset(-.05) recast(connected) color($col1) msymbol($sym1) label("Women"))
		(f0_`k', keep(*.childage) drop(18.childage) offset(+.05) recast(connected) color($col2) msymbol($sym2) label("Men"))
		(f1_`k', keep(18.childage) offset(-.05) recast(connected) color($col1) msymbol($sym1) label("Women"))
		(f0_`k', keep(18.childage) offset(+.05) recast(connected) color($col2) msymbol($sym2) label("Men")),
		title("{bf:`title'}")
		xtitle("Age of youngest child")
		ytitle("`ytitle'")
		relocate(
			18.childage = -3
			0.childage = 0
			1.childage = 1
			2.childage = 2
			3.childage = 3
			4.childage = 4
			5.childage = 5
			6.childage = 6
			7.childage = 7
			8.childage = 8
			9.childage = 9
			10.childage = 10
			11.childage = 11
			12.childage = 12
			13.childage = 13
			14.childage = 14
			15.childage = 15
			16.childage = 16
			17.childage = 17)
		xlabel(-3 "None" 0 "<1" 3 "3" 6 "6" 9 "9" 12 "12" 15 "15" 18 "18")
		yscale(range(`yrange'))
		ylabel(`ylabel')
		yline(0)
		addplot(
			rarea rmax rmin rval if inrange(rval, 5.5, 12.5), color($ltgs) plotregion(margin(t=0 b=0)) below ||
			scatteri 0 5.5 0 12.5, recast(line) color(black) below)
		vertical
		baselevels
		plotregion(margin(l=3 r=3 t=0 b=0))
		legend(rows(1) size(*0.8) order(4 6) label(4 "Women") label(6 "Men"))
		rescale(100);
	#delimit cr

	tempfile g`k'
	graph save "`g`k''"
}

grc1leg "`graw'" "`gadj'"
nicepdf "$basepath/output/careers.pdf", panels(2) indirect replace

* Close the log file
unlaunch
